#include "StdAfx.h"
//-------------------------------------------------------------------------------------------------
//SelectTool.cpp : Tool used to draw all Properties for Image - allows individual ImageObjects to be selected and edited   
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk July 2011
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------

#include <string>

#include "SelectTool.h"
#include "PtShapeType.h"
#include "EllipseShapeType.h"


SelectTool::SelectTool(void) :
	_pDrawingTools('\0')
{
	SetImageObjectType('\0');
}

SelectTool::SelectTool(ImageObjectType *pImageObjectType)
{
	SetImageObjectType(pImageObjectType);
}

SelectTool::~SelectTool(void)
{
}

int		SelectTool::InsertDynMenuItem(void* pMenuPopup, int iMenuIndex)
{
	int rc = 0;

	CMFCPopupMenu* pPopup = reinterpret_cast<CMFCPopupMenu*>(pMenuPopup);
	if (pPopup)
	{
		CString menuText(GetImageObjectType()->GetMenuName());
		CMFCToolBarMenuButton button1(GetImageObjectType()->GetResourceId(), NULL, -1, menuText);
		rc = pPopup->InsertItem (button1, iMenuIndex);
		SetMenuIndex(rc);
	}
	return rc;
}

bool	SelectTool::DrawImageDynMenu(void* pDC, const void* pMenuButton, ImageRect& menuIconImage, bool selected)
{
	bool rc = false;

	CDC* pDevContext = reinterpret_cast<CDC*>(pDC);
	const CMFCToolBarMenuButton* pButton = reinterpret_cast<const CMFCToolBarMenuButton*>(pMenuButton);
	if (pButton && pDevContext)
	{
		if (GetResourceId() == pButton->m_nID)
		{
			CBrush br (GetImageObjectType()->GetPenColour());

			CRect rect(menuIconImage.GetTopLeft().x, menuIconImage.GetTopLeft().y, menuIconImage.GetBotRight().x, menuIconImage.GetBotRight().y);
			rect.DeflateRect (2, 2);

			pDevContext->FillRect (rect, &br);

			if (selected)
			{
				CBrush dot (GetImageObjectType()->GetInversePenColour());
				rect.DeflateRect (5, 5);
				pDevContext->FillRect (rect, &dot);
			}
		
			rc = true;
		}
	}
	return rc;
}

void	SelectTool::DrawImageObject(void *pGraphics, ImageObject *pImageObject, bool selected)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("SelectTool::DrawImageObject()", "Error: Select Tool just used for selecting and drawing existing image objects. There aren't any Select Tool type image objects");
#endif
//!!!!!!!!!!!!!!!
	ASSERT(0);
}


ImageObject *SelectTool::DoLButtonDown(UINT nFlags, const ImagePt& point, ImageProps *pImageProps) 
{
	ImageObject * rc = '\0';

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("SelectTool::DoLButtonDown()", "Todo: select any Image Object in ImageProps if point (x=%d, y=%d) is within its extent", point.x, point.y);
#endif
//!!!!!!!!!!!!!!!

	if (pImageProps != '\0')
	{
		rc = pImageProps->GetSelImageObject();
	}

	return rc;
}


bool	SelectTool::DoLButtonUp(UINT nFlags, const ImagePt& point, ImageObject *pSelImageObject)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("SelectTool::DoLButtonUp()", "Todo: implement end marque select point (x=%d, y=%d)", point.x, point.y);
#endif
//!!!!!!!!!!!!!!!

	rc = true;

	return rc;
}

bool	SelectTool::DoMouseMove(UINT nFlags, const ImagePt& point, ImageObject *pSelImageObject)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("SelectTool::DoMouseMove()", "Todo: implement start marque select point (x=%d, y=%d)", point.x, point.y);
#endif
//!!!!!!!!!!!!!!!

	rc = true;

	return rc;
}


bool	SelectTool::IsCompatible(ImageObject *pImageObject)
{
	bool rc = true;		//select tool is compatible with all types of ImageObject

	return rc;
}

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------

